# !/usr/bin python3
# encoding: utf-8 -*-
# 创建flask应用程序实例
import time

from flask import Flask, request, make_response

app = Flask(__name__)
# get请求无参
#使用flask框架装饰器，定义路径
@app.route('/')
def hello_world():
    return 'hello'
# get请求 有参数
@app.route('/getparams')
def get_params():
    id=request.args.get('id')
    return f'{id}'
# post请求  表单
@app.route('/post_data',methods=['POST'])
def post_data():
    username=request.form.get('username')
    password=request.form.get('password')
    return f'欢迎{username},密码{password}'
# post请求 json
@app.route('/post_json',methods=['POST'])
def post_json():
    username = request.json.get('username')
    password = request.json.get('password')
    return {'status':0,'message':'success'}

# put请求 路径参数
@app.route('/put/<id>/change',methods=['PUT'])
def put_data(id):
    return f'数据{id}修改成功'
# delete请求
@app.route('/delete/<id>/order',methods=['delete'])
def del_data(id):
    return f'订单{id}删除成功'
# 模拟响应状态码500
@app.route('/return/statuscode',methods=['POST'])
def return_status():
    response=make_response()
    response.status_code = 500
    return response

# 延迟10s
@app.route('/delay',methods=['POST'])
def delay():
    time.sleep(6)
    return '延迟6秒后得到结果'
if __name__ == '__main__':
    app.run(debug=True)